#! /usr/bin/python3
# coding=utf-8
# @time: 2025/10/23 19:30
# @Author:鹤川
import time

from selenium.webdriver.chrome import webdriver
from selenium.webdriver.common.by import By



class AutoWebEcshop():
    # 3个属性
    ename = (By.CSS_SELECTOR, "input[name='username']")
    epwd = (By.CSS_SELECTOR, "input[name='password']")
    ebut = (By.CSS_SELECTOR, "input[name='submit']")

    def login(self):
        # 行为
        driver = webdriver.WebDriver()
        driver.get("http://192.168.234.149/user.php")
        driver.maximize_window()
        driver.find_element(*self.ename).send_keys("test")
        time.sleep(0.5)
        driver.find_element(*self.epwd).send_keys("123456")
        time.sleep(0.5)
        driver.find_element(*self.ebut).click()
        time.sleep(4)

class AddMessage():
    eZh = (By.XPATH,"//font[@id='ECS_MEMBERZONE']/a[1]")
    eUM = (By.XPATH,"//div[@class='userMenu']/a[6]")
    eLYBT = (By.XPATH,"//input[@name='msg_title']")
    eNR = (By.XPATH,"//textarea[@name='msg_content']")
    eSM = (By.XPATH,"//input[@class='bnt_bonus']")
    def add_message(self):
        # 行为
        driver = webdriver.WebDriver()
        # 点击
        driver.find_element(*self.eZh).click()
        # 点击留言
        driver.find_element(*self.eUM).click()
        time.sleep(0.5)
        driver.find_element(*self.eLYBT).send_keys("测试")
        time.sleep(0.5)
        driver.find_element(*self.eNR).send_keys("这是10月23日作业的留言")
        time.sleep(0.5)
        # self.driver.find_element_by_xpath("//input[@name='message_img']").send_keys(self.myFile)
        # time.sleep(0.5)
        driver.find_element(*self.eSM).click()
        time.sleep(2)

if __name__ == '__main__':
    autoWeb = AutoWebEcshop()
    addMessage = AddMessage()
    autoWeb.login()
    addMessage.add_message()


